import {
  getLineCodeListNew,
} from "@/api/report/mesProdOrderPlanPassRatio.js"
import moment from "moment";
import { getTeamCodeList } from "@/api/employee/mesUserExtend";
export const reportLineSearchConfig = {
  data () {
    const self = this
    var choiceDate = null
    return {
      reportLineSearchConfig: {
        searchTimeType: {
          type: "radio-button",
          layout: 3,
          labelWidth: '10px',
          options: [{ text: $i18n.t("common.sevenDays"), value: "4" }, { text: $i18n.t("common.thirtyDays"), value: "5" }],
          on: {
            change: (val) => {
              self.timeChange(val)
            }
          }
        },
        actualEndDate: {
          // labelWidth: "170px",
          type: "daterange",
          layout: 7,
          label: $i18n.t("abnormalProcessAnalysis.actualEndDate"),
          attrs: {
            valueFormat: "yyyy-MM-dd",
            searchArrKey: ["actualEndDateMin", "actualEndDateMax"],
            clearable: false,
            pickerOptions: {
              onPick: ({ maxDate, minDate }) => {
                // 把选择的第一个日期赋值给一个变量。
                choiceDate = minDate.getTime()

                // 如何你选择了两个日期了，就把那个变量置空
                if (maxDate) choiceDate = ''
              },
              disabledDate: (time) => {
                // 如何选择了一个日期
                if (choiceDate) {
                  // 7天的时间戳
                  const one = 30 * 24 * 3600 * 1000
                  // 当前日期 - one = 7天之前
                  const minTime = choiceDate - one
                  // 当前日期 + one = 7天之后
                  const maxTime = choiceDate + one
                  return time.getTime() < minTime || time.getTime() > maxTime
                } else {
                  // 如果没有选择日期，就要限制不能选择今天及以后
                  // return time.getTime() > Date.now();
                }
              }
            }
          }
        },
        workshopCode: {
          label: $i18n.t("mesProdOrderPlanPassRatio.workshopName"),
          type: "select",
          // labelWidth: "80px",
          layout: 5,
          prop: {
            value: "modelingCode",
            text: "modelingName",
          },
          options: async (data) => {
            const params = {
              modelingCode: self.$store.getters.factoryCode,
              level: 4,
              modelingType: "0",
            };
            const list = await getLineCodeListNew(params);
            return list.data.result;
          },
        },
        lineCode: {
          // labelWidth: "80px",
          // labelWidth: '90px',
          layout: 5,
          label: $i18n.t("mesProdOrderPlanPassRatio.lineName"),
          type: "select",
          prop: {
            value: "modelingCode",
            text: "modelingName",
          },
          optionsLinkageFields: ["workshopCode"],
          options: async (data) => {
            if (data && data.workshopCode) {
              const params = {
                modelingCode: data.workshopCode,
                level: 5,
              };
              const list = await getLineCodeListNew(params);
              return list.data.result;
            } else {
              return []
            }
          },
        },
        workTeamCode: {
          type: "select",labelWidth: "60px",
          label: $i18n.t("common.team"),
          optionsLinkageFields: ["lineCode"],
          isReloadOptions: true,
          attrs: {
            filterable: true,
          },
          prop: {
            value: "teamCode",
            text: "teamName",
          },
          options: async (data) => {
            // const list = await getTeamCodeList();
            // return list.data.result;
            if (data.lineCode) {
              const list = await getTeamCodeList({ lineCode: data.lineCode });
              return list.data.result;
            } else {
              return [];
            }
          },
        },
        searchBtn: {
          labelWidth: "0px",
          layout: 1,
          type: 'input',
          label: ""
        },
        resetBtn: {
          labelWidth: "20px",
          layout: 1,
          type: 'input',
          label: ""
        },
      }
    }
  },
  methods: {
    // timeChange (val) {
    //   if (val == '4') {
    //     this.searchData = { searchTimeType: val, actualEndDate: [moment().subtract(8, 'days').format('YYYY-MM-DD'), moment().subtract(1, 'days').format('YYYY-MM-DD')] }
    //   } else {
    //     this.searchData = { searchTimeType: val, actualEndDate: [moment().subtract(31, 'days').format('YYYY-MM-DD'), moment().subtract(1, 'days').format('YYYY-MM-DD')] }
    //   }
    // }
  }
}
